package cn.source.system.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import cn.source.common.annotation.Log;
import cn.source.common.core.controller.BaseController;
import cn.source.common.core.domain.AjaxResult;
import cn.source.common.enums.BusinessType;
import cn.source.system.domain.TravelFacility;
import cn.source.system.service.ITravelFacilityService;
import cn.source.common.utils.poi.ExcelUtil;
import cn.source.common.core.page.TableDataInfo;

/**
 * 基础设施Controller
 *
 * @author sourcebyte.vip
 * @date 2024-06-19
 */
@RestController
@RequestMapping("/travel/facility")
public class TravelFacilityController extends BaseController
{
    @Autowired
    private ITravelFacilityService travelFacilityService;

    /**
     * 查询基础设施列表
     */
    @PreAuthorize("@ss.hasPermi('travel:facility:list')")
    @GetMapping("/list")
    public TableDataInfo list(TravelFacility travelFacility)
    {
        startPage();
        List<TravelFacility> list = travelFacilityService.selectTravelFacilityList(travelFacility);
        return getDataTable(list);
    }

    /**
     * 获取基础设施详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(travelFacilityService.selectTravelFacilityById(id));
    }

    /**
     * 新增基础设施
     */
    @PreAuthorize("@ss.hasPermi('travel:facility:add')")
    @Log(title = "基础设施", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TravelFacility travelFacility)
    {
        return toAjax(travelFacilityService.insertTravelFacility(travelFacility));
    }

    /**
     * 修改基础设施
     */
    @PreAuthorize("@ss.hasPermi('travel:facility:edit')")
    @Log(title = "基础设施", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TravelFacility travelFacility)
    {
        return toAjax(travelFacilityService.updateTravelFacility(travelFacility));
    }

    /**
     * 删除基础设施
     */
    @PreAuthorize("@ss.hasPermi('travel:facility:remove')")
    @Log(title = "基础设施", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(travelFacilityService.deleteTravelFacilityByIds(ids));
    }

    /**
     * 导出基础设施列表
     */
    @PreAuthorize("@ss.hasPermi('travel:facility:export')")
    @Log(title = "基础设施", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TravelFacility travelFacility)
    {
        List<TravelFacility> list = travelFacilityService.selectTravelFacilityList(travelFacility);
        ExcelUtil<TravelFacility> util = new ExcelUtil<TravelFacility>(TravelFacility.class);
        util.exportExcel(response, list, "基础设施数据");
    }
}
